package com.zyy.controller;

import com.zyy.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @Description: 类描述
 * @Author: zyy
 * @Date: 2023/05/12 18:53
 */
@RestController
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @GetMapping("/parse/{keyword}")
    public Boolean parseContent(@PathVariable("keyword") String keyword) {
        try {
            return goodsService.parseContent(keyword);
        } catch (Exception e) {
            return false;
        }
    }

    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String, Object>> search(@PathVariable("keyword") String keyword,
                                            @PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
        try {
            return goodsService.highlightSearch(keyword, pageNo, pageSize);
        } catch (IOException e) {
            return null;
        }
    }
}
